/**
 * Created by Administrator on 2017/3/17 0017.
 */
Page3={
    Create:function(){
        var page={};
        var whole=new PIXI.DisplayObjectContainer();

        var bg=PSP("page3_1");
        whole.addChild(bg);
        bg.alpha=0;

        var arr_square=[];
        for(var z=0;z<50;z++){
            for(var y=0;y<37;y++){
                var square=new PIXI.Graphics();
                square.beginFill(0xeb164a,1);
                square.drawRect(0,0,20,22.72);
                square.x=313+60;square.y=631+174;
                // square.x=313+60+Math.random()*10;square.y=631+174+Math.random()*50;
                arr_square.push(square);
                whole.addChild(square);
                square.blendMode=PIXI.BLEND_MODES.MULTIPLY;
                // console.log(z,y);
            }
        }
        var line=new PIXI.Graphics();
        line.beginFill(0xffffff,1);
        line.lineStyle(1,0xffffff,2);
        line.moveTo(293,950);
        line.lineTo(449,950);
        whole.addChild(line);

        var word1=PSP("page3_2");
        var word2=PSP("page3_3");


        whole.addChild(word1);whole.addChild(word2);
        word1.x=219;word1.y=1007;
        word2.x=144;word2.y=1054;


        line.alpha=0;word1.alpha=0;word2.alpha=0;

        var buildingBG=PSP("page3_4");
        // whole.addChild(buildingBG);
        buildingBG.x=58+buildingBG.width/2;buildingBG.y=69+buildingBG.height/2;
        buildingBG.anchor.set(0.5);
        buildingBG.alpha=0;

        var manBG=PSP("page3_5");
        // whole.addChild(manBG);
        manBG.x=58+manBG.width/2;manBG.y=69+manBG.height/2;
        manBG.anchor.set(0.5);
        manBG.alpha=0;

        var man2=PSP("page3_6");
        whole.addChild(man2);
        man2.anchor.set(0.5);
        man2.x=252+man2.width/2;man2.y=110+man2.height/2;
        man2.alpha=0;

        var arr_alphabet=[];
        for(var i=9;i<=18;i++) {
            var alphabet = PSP("page3_" + i);
            whole.addChild(alphabet);
            arr_alphabet.push(alphabet);

            var xx,yy;
            switch (i){
                case 9:xx=65;yy=49.8;break;
                case 10:xx=149.45;yy=48;break;
                case 11:xx=410;yy=49.6;break;
                case 12:xx=65;yy=199.05;break;
                case 13:xx=347.3;yy=199.05;break;
                case 14:xx=65;yy=318.55;break;
                case 15:xx=392.25;yy=317.05;break;
                case 16:xx=65;yy=442.35;break;
                case 17:alphabet.anchor.set(1,0);xx=65+alphabet.width;yy=576.05;break;
                case 18:alphabet.anchor.set(0.5);xx=65+alphabet.width/2;yy=754.85+alphabet.height/2;break;
            }
            alphabet.alpha=0;
            alphabet.x=xx;alphabet.y=yy;
        }


        var wholeAlphabet=PSP("page3_8");
        wholeAlphabet.anchor.set(0.5);
        wholeAlphabet.x=65+wholeAlphabet.width/2;wholeAlphabet.y=48+wholeAlphabet.height/2;
        whole.addChild(wholeAlphabet);
        wholeAlphabet.alpha=0;

        var mask=PSP("page3_8")
        whole.addChild(mask);
        mask.x=65;mask.y=48;

        var man=PSP("page3_6");
        whole.addChild(man);
        man.anchor.set(0.5);
        man.x=252+man.width/2;man.y=110+man.height/2;
        man.alpha=0;
        man.scale.set(3);
        man.mask=mask;















        whole.on("pointerdown",function(){
            whole.interactive=false;
            TweenMax.to(manBG.scale,1,{x:0,y:0,ease:Cubic.easeInOut});
            TweenMax.to(manBG,1,{x:397,y:845,alpha:0,ease:Cubic.easeInOut});
            TweenMax.to(line,0.7,{delay:0.1,alpha:0,x:0,ease:Cubic.easeOut});
            TweenMax.to(word1,0.7,{delay:0.3,alpha:0,x:word1.x+50,ease:Cubic.easeOut});
            TweenMax.to(word2,0.7,{delay:0.5,alpha:0,x:word2.x+70,ease:Cubic.easeOut});


            TweenMax.to(man,0.01,{alpha:0});


            TweenMax.to(wholeAlphabet,0.7,{alpha:0,ease:Cubic.easeOut});
            // TweenMax.to(wholeAlphabet.scale,0.7,{x:0,y:0,ease:Cubic.easeOut});
            for(var z=0;z<arr_alphabet.length;z++){
                TweenMax.to(arr_alphabet[z],0.01,{alpha:0,ease:Cubic.easeOut});
            }

            TweenMax.to(bg,0.5,{alpha:0});


            man2.alpha=1;
            TweenMax.to(man2,1,{width:167,height:489,x:320+167/2,y:621+489/2,ease:Cubic.easeInOut});
            TweenMax.to(man2,0.01,{delay:4,alpha:0});
            dispear();
        });


        function dispear(){
            for(var z=0;z<arr_square.length;z++){
                TweenMax.to(arr_square[z],1,{delay:0.0001*z*Math.random()-0.00005,alpha:0,x:740*Math.random(),y:1136*Math.random(),ease:Cubic.easeInOut});
            }
            document.dispatchEvent(new CustomEvent("PageChange",{detail:4}));
        }




        page.start=function(){
            setTimeout(function(){
                whole.interactive=true;
            },5500)

            for(var z=0;z<arr_square.length;z++){
                var a=arr_square[z];
                TweenMax.to(a,2,{delay:0.0001*z*Math.random()-0.00005,x:z/50*20,y:z%50*22.72,rotation:Math.PI/180*360,ease:Cubic.easeInOut});
            }
            TweenMax.to(bg,10,{alpha:1});

            var delayTime=1.5;
            line.x-=30;
            word1.x-=50;
            word2.x-=70;
            TweenMax.to(line,1,{delay:2+delayTime,alpha:1,x:0,ease:Cubic.easeOut});
            TweenMax.to(word1,1,{delay:2.2+delayTime,alpha:1,x:word1.x+50,ease:Cubic.easeOut});
            TweenMax.to(word2,1,{delay:2.4+delayTime,alpha:1,x:word2.x+70,ease:Cubic.easeOut});



            TweenMax.to(buildingBG,1,{delay:1.3,alpha:1,ease:Cubic.easeOut});
            TweenMax.to(buildingBG.scale,0.7,{delay:2.3+delayTime,x:2,y:2,ease:Cubic.easeOut});
            TweenMax.to(buildingBG,0.7,{delay:2.1+delayTime,alpha:0,ease:Cubic.easeOut});

            manBG.scale.set(3);
            TweenMax.to(manBG,1,{delay:2.3+delayTime,alpha:1});
            TweenMax.to(manBG.scale,1,{delay:2.3+delayTime,x:1,y:1,alpha:1,ease:Cubic.easeInOut});

            TweenMax.to(man,1,{delay:3.8,alpha:1,ease:Cubic.easeOut});
            TweenMax.to(man.scale,1,{delay:3.8,x:1,y:1,ease:Cubic.easeOut});




            setTimeout(function(){
                wholeAlphabet.alpha=1;
                for(var z=0;z<arr_alphabet.length;z++){
                    arr_alphabet[z].alpha=0;
                }
            },4000)

            for(var k=0;k<10;k++){
                var value;
                switch (k){
                    case 0:value=-30;arr_alphabet[k].x+=value;
                        TweenMax.to(arr_alphabet[k],1,{delay:0.2*k+delayTime,alpha:1,x:arr_alphabet[k].x-value,ease:Cubic.easeOut});
                        break;
                    case 1:value=-30;arr_alphabet[k].x+=value;
                        TweenMax.to(arr_alphabet[k],1,{delay:0.2*k+delayTime,alpha:1,x:arr_alphabet[k].x-value,ease:Cubic.easeOut});
                        ;break;
                    case 2:value=-30;arr_alphabet[k].x+=value;
                        TweenMax.to(arr_alphabet[k],1,{delay:0.2*k+delayTime,alpha:1,x:arr_alphabet[k].x-value,ease:Cubic.easeOut});
                        ;break;
                    case 3:value=30;arr_alphabet[k].x+=value;
                        TweenMax.to(arr_alphabet[k],1,{delay:0.2*(k+1)+delayTime,alpha:1,x:arr_alphabet[k].x-value,ease:Cubic.easeOut});
                        ;break;
                    case 4:value=30;arr_alphabet[k].x+=value;
                    TweenMax.to(arr_alphabet[k],1,{delay:0.2*(k-1)+delayTime,alpha:1,x:arr_alphabet[k].x-value,ease:Cubic.easeOut});
                    ;break;
                    case 5:value=-30;arr_alphabet[k].x+=value;
                        TweenMax.to(arr_alphabet[k],1,{delay:0.2*k+delayTime,alpha:1,x:arr_alphabet[k].x-value,ease:Cubic.easeOut});
                        ;break;
                    case 6:value=30;arr_alphabet[k].x+=value;
                        TweenMax.to(arr_alphabet[k],1,{delay:0.2*(k-1)+delayTime,alpha:1,x:arr_alphabet[k].x-value,ease:Cubic.easeOut});
                        ;break;
                    case 7:value=30;arr_alphabet[k].y+=value;
                        TweenMax.to(arr_alphabet[k],1,{delay:0.2*(k-1)+delayTime,alpha:1,y:arr_alphabet[k].y-value,ease:Cubic.easeOut});
                        arr_alphabet[k].scale.set(2);
                        TweenMax.to(arr_alphabet[k].scale,1,{delay:0.2*(k-1)+delayTime,x:1,y:1,ease:Cubic.easeOut});
                        ;break;
                    case 8:value=40;arr_alphabet[k].y+=value;
                        TweenMax.to(arr_alphabet[k],1,{delay:0.2*(k-1)+delayTime,alpha:1,y:arr_alphabet[k].y-value,ease:Cubic.easeOut});
                        arr_alphabet[k].scale.set(2);
                        TweenMax.to(arr_alphabet[k].scale,1,{delay:0.2*(k-1)+delayTime,x:1,y:1,ease:Cubic.easeOut});
                        ;break;
                    case 9:value=70;arr_alphabet[k].y+=value;
                        TweenMax.to(arr_alphabet[k],1,{delay:0.2*(k)+delayTime,alpha:1,y:arr_alphabet[k].y-value,ease:Cubic.easeOut});
                        arr_alphabet[k].scale.set(3);
                        TweenMax.to(arr_alphabet[k].scale,1,{delay:0.2*(k)+delayTime,x:1,y:1,ease:Cubic.easeOut});
                        ;break;
                }


            }




        }

        page.In=function(){

        }
        page.Out=function(){

        }
        page.ReturnWhole=function(){
            return whole;
        }
        return page;
    }
}
